﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ExtendPropertyLib.WPF;
using ExtendPropertyLib;
using System.Collections.ObjectModel;
using ExORMDesginer.Models;
using ExORMDesginer.Services;
using System.Threading.Tasks;
namespace ExORMDesginer.UserControls.Dialogs
{
    public class SolutionBowserDialogInfo : BusinessInfoBase<SolutionBowserDialogInfo>
    {
        public SolutionBowserDialogInfo()
        {
            TaskEx.Run(async() =>
            {
                IsLoaded = true;
                await LoadPropertys();
                if (ProjectItemInfoList != null && ProjectItemInfoList.Count > 0)
                {
                    CurrentItemInfo = ProjectItemInfoList[0];
                }
                IsLoaded = false;
            });
        }

        private async Task LoadPropertys()
        {
           this.ProjectItemInfoList = await VSIDEService.GetPathInfo();
        }

        
        public static ExtendProperty IsLoadedProperty = RegisterProperty(m => m.IsLoaded);
        /// <summary>
        /// 载入完成
        /// </summary>
        public bool IsLoaded
        {
            set
            {
                SetValue(IsLoadedProperty, value);
            }
            get
            {
                return (bool)GetValue(IsLoadedProperty);
            }
        }


        public static ExtendProperty ProjectItemInfoListProperty = RegisterProperty(m => m.ProjectItemInfoList);

        /// <summary>
        /// 项目文件信息
        /// </summary>
        public ObservableCollection<ProjectItemInfo> ProjectItemInfoList
        {
            set
            {
                SetValue(ProjectItemInfoListProperty, value);
            }
            get
            {
                return (ObservableCollection<ProjectItemInfo>)GetValue(ProjectItemInfoListProperty);
            }
        }


        
        public static ExtendProperty CurrentItemInfoProperty = RegisterProperty(m => m.CurrentItemInfo);
        /// <summary>
        /// 当前选择的项目信息
        /// </summary>
        public ProjectItemInfo CurrentItemInfo
        {
            set
            {
                SetValue(CurrentItemInfoProperty, value);
            }
            get
            {
                return (ProjectItemInfo)GetValue(CurrentItemInfoProperty);
            }
        }

        public void Save(string fileName)
        {
            if(CurrentItemInfo!=null)
                this.CurrentItemInfo.AddFromFile(fileName);
        }

    }
}
